<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*,hotel.entity.*"%>
<%@include file="../link.html"%>
<!DOCTYPE html>
<script type="text/javascript">
$(document).ready(function() {
	$("#btn-close").click( function () { 
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭 
	});
});

function saveCategory(){
	var index=$('#btn-submit').attr('class').indexOf("disabled");
	var form = new FormData(document.getElementById("categoryForm"));
	if(index==-1){//disabled的下标为-1说明确定按钮可用
		$.ajax({
	        type:"post",
	        url:"addCategory",
	        //data: $('#categoryForm').serialize(),//表单数据
	        processData: false,  
	        contentType: false,
	        data: form,
	        success: function(data){
				layer.msg('创建成功', {icon: 1, time: 800}, function(){//关闭后执行的操作
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭 
					});  
	        }
	    });
	}
	return false;
}
</script>

<div style="padding-top:25px;">
	<form id="categoryForm" action="addCategory" method="post" class="form-horizontal" 
	data-toggle="validator" role="form" enctype="multipart/form-data">
		<div class="form-group has-feedback">
			<label class="col-sm-4 control-label">房间类型名称</label>
			<div class="col-sm-5">
				<input id="categoryName" name="categoryName" class="form-control" autofocus="autofocus" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>

		<div class="form-group">
			<label class="col-sm-4 control-label">床型</label>
			<div class="col-sm-5">
				<select name="bed.bedid" id="Select_Bed" class="form-control">
				<% 
					List<Bed> list=(List<Bed>)request.getAttribute("bedList");
					for(Bed b:list){
						out.print("<option value='"+b.getBedid()+"'>"+b.getName()+"</option>");
					}
				%>
				</select>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">可住人数</label>
			<div class="col-sm-5">
				<input id="capacity" name="capacity" class="form-control" 
				type="number" value="1" min="1" max="20" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">详细说明</label>
			<div class="col-sm-5">
				<textarea id="detail" name="detail" class="form-control"></textarea>
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-4 control-label">上传图片</label>
			<div class="col-sm-5">
				<input type="file" name="category_pic">
			</div>
		</div>
		
		<div class="box-footer"></div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label"></label>
			<div class="col-sm-5">
				<div class="pull-right">
					<button id="btn-submit" type="submit" class="btn btn-primary" onClick="return saveCategory()">
						<i class="fa fa-floppy-o "></i> 确定
					</button>
					<button id="btn-close" class="btn btn-close btn-primary" type="button">
						<i class="fa fa-remove"></i> 关闭
					</button>
				</div>
			</div>
		</div>
	</form>
</div>